<template>
	<div class="app-container">
		<el-tabs type="card" @tab-click="handleClick" v-model="activeName">
			<el-tab-pane label="最终结果" name="first">
				<IndexAssess1Form />
			</el-tab-pane>
			<el-tab-pane label="中间结果" name="second">
				<el-table v-loading="middleResultloading" :data="middleResultList">
					<el-table-column label="生成时间" align="center" prop="createTime" />
					<el-table-column label="生成人" align="center" prop="createUserName" />

					<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
						<template #default="scope">
							<el-button type="text" @click="handleEdit(scope.row)">修改</el-button>
							<el-button type="text" @click="handleReplace(scope.row)">替换为最终结果</el-button>
							<el-button type="text" @click="handleDelete(scope.row)">删除</el-button>
						</template>
					</el-table-column>
				</el-table>

				<pagination v-show="total > 0" :total="total" v-model:page="queryParams.page" v-model:limit="queryParams.rows"
					@pagination="getList" />
			</el-tab-pane>
		</el-tabs>
	</div>
</template>

<script setup name="indexAssess1Form">
import {getDzzhTaskModel, replaceFinalResult, deleteCenter } from "@/api/sandliquidAssess/indexAssess1";
import IndexAssess1Form from './indexAssess1Form.vue'

const route = useRoute();
const router = useRouter();
const { proxy } = getCurrentInstance();
const activeName = ref("first");
const middleResultList = ref([]);
const middleResultloading = ref(true);
const total = ref(0);

const data = reactive({
	queryParams: {
		page: 1,
		rows: 10,
	},
});

const { queryParams } = toRefs(data);

/** 删除按钮操作 */
function handleDelete(row) {
	proxy.$modal.confirm('是否确认删除？').then(function () { }).then(() => {
		deleteCenter({
			"dmslId": row.dmslId,
			//"versionCode": drillVersion.value
		}).then(response => {
			proxy.$modal.msgSuccess("删除成功");
			getList();
		});
	}).catch(() => { });
}
//获取中间结果列表
function getList() {
	middleResultloading.value = true;
	getDzzhTaskModel({
		...queryParams.value,
		"taskId": route.query.taskId
	}).then(response => {
		middleResultloading.value = false;
		middleResultList.value = response.data.rows;
		total.value = response.data.total;
	});
}
//修改
function handleEdit(row) {
	router.push({
		path: "/stAnalysisAssess/indexAssess1Form",
		query: {
			...route.query,
			metaTitle: `修改${route.query.metaTitle}中间结果`,
			dmslId: row.dmslId
		}
	})
}
//替换为最终结果
function handleReplace(row) {
	var taskId = row.taskId;
	proxy.$confirm('请选择是否将被替换的结果存为中间结果选择“否”，被替换的结果作废', '系统提示', {
		confirmButtonText: '是',
		cancelButtonText: '否',
		type: 'warning'
	}).then(function () { }).then(() => {
		replaceFinalResult({
			//"versionCode": form.value.drillVersion,
			"dmslId": row.dmslId,
			"flag": "1",
			"taskId": taskId
		}).then(response => {
			proxy.$modal.msgSuccess(response.data);
			getList();
		});
	}).catch(() => {
		replaceFinalResult({
			"dmslId": row.dmslId,
			"flag": "2",
			"taskId": taskId
		}).then(response => {
			proxy.$modal.msgSuccess(response.data);
			getList();
		});
	});
}
//切换标签页
function handleClick(tab, event) {
	if (tab.props.name == "second") {
		getList();
	}
}

const setSpan = (tableData) => {
	let rowSpan = []
	tableData.map((item, index) => {
		if(rowSpan[index] || rowSpan[index]==0){
			return
		}
		rowSpan.push(item.num)
		if (item.num > 0) {
			for (let i = index + 1; i < item.num + index; i++) {
				rowSpan[i] = 0
			}
		}
	})
	return rowSpan
}
</script>